package com.tengju.support.domain.model.wx;

import com.tengju.support.domain.shared.DomainException;
import com.tengju.support.domain.shared.DomainExceptionCode;
import lombok.Builder;
import lombok.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

public class CreateWechatUserForm {

    /**
     * 成员UserID
     */
    String userId;
    /**
     * 成员名称
     */
    String name;
    /**
     * 成员别名
     */
    String alias;
    /**
     * 手机号码
     */
    String mobile;
    /**
     * 成员所属部门id列表
     */
    List<DepartmentId> department;
    /**
     * 部门内的排序值
     */
    List<Integer> order;
    /**
     * 职务信息
     */
    String position;
    /**
     * 性别
     */
    Gender gender;
    /**
     * 邮箱
     */
    String email;
    /**
     * 表示在所在的部门内是否为上级
     */
    IsLeader isLeader;
    /**
     * 启用/禁用成员
     */
    Enable enable;
    /**
     * 成员头像的mediaId
     */
    String avatarMediaId;
    /**
     * 座机
     */
    String telephone;
    /**
     * 地址
     */
    String address;
    /**
     * 主部门
     */
    DepartmentId mainDepartment;
    /**
     * 自定义字段
     */
    WechatUserExtra extAttr;
    /**
     * 是否邀请该成员使用企业微信
     */
    Boolean toInvite;
    /**
     * 对外职务
     */
    String externalPosition;
    /**
     * 成员对外信息
     */
    ExternalProfile externalProfile;

    public CreateWechatUserForm() {
    }

    public CreateWechatUserForm(String userId, String name, String mobile, List<DepartmentId> department) {

        if (StringUtils.isEmpty(userId)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员userId为空");
        }
        if (StringUtils.isEmpty(name)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员名字为空");
        }
        if (StringUtils.isEmpty(mobile)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员手机号为空");
        }
        if (CollectionUtils.isEmpty(department)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员部门信息为空");
        }
        this.userId = userId;
        this.name = name;
        this.mobile = mobile;
        this.department = department;
    }

    public CreateWechatUserForm(String userId, String name, String alias, String mobile, List<DepartmentId> department, List<Integer> order, String position, Gender gender, String email, IsLeader isLeader, Enable enable, String avatarMediaId, String telephone, String address, DepartmentId mainDepartment, WechatUserExtra extAttr, Boolean toInvite, String externalPosition, ExternalProfile externalProfile) {

        if (StringUtils.isEmpty(userId)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员userId为空");
        }
        if (StringUtils.isEmpty(name)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员名字为空");
        }
        if (StringUtils.isEmpty(mobile) || StringUtils.isEmpty(email)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员手机号与email都为空");
        }
        if (CollectionUtils.isEmpty(department)) {
            throw DomainException.error(DomainExceptionCode.INVALID_DATA,"成员部门信息为空");
        }

        this.userId = userId;
        this.name = name;
        this.alias = alias;
        this.mobile = mobile;
        this.department = department;
        this.order = order;
        this.position = position;
        this.gender = gender;
        this.email = email;
        this.isLeader = isLeader;
        this.enable = enable;
        this.avatarMediaId = avatarMediaId;
        this.telephone = telephone;
        this.address = address;
        this.mainDepartment = mainDepartment;
        this.extAttr = extAttr;
        this.toInvite = toInvite;
        this.externalPosition = externalPosition;
        this.externalProfile = externalProfile;
    }


    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public List<DepartmentId> getDepartment() {
        return department;
    }

    public void setDepartment(List<DepartmentId> department) {
        this.department = department;
    }

    public List<Integer> getOrder() {
        return order;
    }

    public void setOrder(List<Integer> order) {
        this.order = order;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public IsLeader getIsLeader() {
        return isLeader;
    }

    public void setIsLeader(IsLeader isLeader) {
        this.isLeader = isLeader;
    }

    public Enable getEnable() {
        return enable;
    }

    public void setEnable(Enable enable) {
        this.enable = enable;
    }

    public String getAvatarMediaId() {
        return avatarMediaId;
    }

    public void setAvatarMediaId(String avatarMediaId) {
        this.avatarMediaId = avatarMediaId;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public DepartmentId getMainDepartment() {
        return mainDepartment;
    }

    public void setMainDepartment(DepartmentId mainDepartment) {
        this.mainDepartment = mainDepartment;
    }

    public WechatUserExtra getExtAttr() {
        return extAttr;
    }

    public void setExtAttr(WechatUserExtra extAttr) {
        this.extAttr = extAttr;
    }

    public Boolean getToInvite() {
        return toInvite;
    }

    public void setToInvite(Boolean toInvite) {
        this.toInvite = toInvite;
    }

    public String getExternalPosition() {
        return externalPosition;
    }

    public void setExternalPosition(String externalPosition) {
        this.externalPosition = externalPosition;
    }

    public ExternalProfile getExternalProfile() {
        return externalProfile;
    }

    public void setExternalProfile(ExternalProfile externalProfile) {
        this.externalProfile = externalProfile;
    }
}
